Came across this error when placing a where clause on linq query against an IEnumerable menuitem list to get a menuitem.
Unable to cast object of type 'WhereEnumerableIterator`1[System.Windows.Controls.MenuItem]' to type 'System.Windows.Controls.MenuItem'
Was quite confusing and no real answers on the web. Worked out that my where clause could probable return more than one menuitem entry (even though I know there is only one result) and therefore I needed to add the .first on the end of the linq query and it solved the issue.
Putting this out there in case others need a hint.